package com.wyw.hemerocallis.service;

import com.wyw.hemerocallis.service.hystrix.AuthorityFeignClientFallback;
import com.wyw.hemerocallis.service.hystrix.AuthorityFeignClientFallbackFactory;
import com.wyw.hemerocallis.vo.JwtToken;
import com.wyw.hemerocallis.vo.UsernameAndPassword;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

/**
 * 与Authority服务通信的Feign Client接口定义
 *  由OpenFeign生成代理类
 *  contextId 当有多个鉴权中心进行指定的时候，可以通过contextId进行指定
 *
 * @author Mr Wu    yewen.wu.china@gmail.com
 * <p>
 * Update History:
 * Author        Time            Content
 */
@FeignClient(contextId = "AuthorityFeignClient", value = "hemerocallis-authority-center",
//fallback = AuthorityFeignClientFallback.class
fallbackFactory = AuthorityFeignClientFallbackFactory.class
)
public interface AuthorityFeignClient {

    /**
     * 通过OpenFeign访问Authority获取Token
     *  consumes与produces可以不指定，但是如果想使用feign原生api，需要指定
     */
    @RequestMapping(value = "/hemerocallis-authority-center/authority/token",
            method = RequestMethod.POST,
            consumes = "application/json", produces = "application/json")
    JwtToken getTokenByFeign(@RequestBody UsernameAndPassword usernameAndPassword);
}
